package com.bjb.vr.manager.controller;

import com.bjb.vr.common.ao.ResContentGroupAo;
import com.bjb.vr.common.ao.ResGroupAo;
import com.bjb.vr.common.dto.ResGroup;
import com.bjb.vr.common.result.BaseErrorCode;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.ResGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 分组管理
 *
 * @author maxingchen
 * @version 1.0
 * @date 2022/5/5 2:40 下午
 */
@RestController
@RequestMapping("/api/manager/v1")
public class GroupController {

    @Autowired
    ResGroupService groupService;

    /**
     * 分组管理的查询列表接口
     *
     * @param resGroupAo
     * @return
     */
    @PostMapping("/queryGroupAllInfos")
    public BaseResult queryGroupAllInfos(@RequestBody ResGroupAo resGroupAo) {
        return CommonResult.Ok().setResult(groupService.queryGroupAllInfos(resGroupAo));
    }


    /**
     * 分组管理的新增列表接口
     *
     * @param resGroupAo
     * @return
     */
    @PostMapping("/addGroupList")
    public BaseResult addPlaylist(@RequestBody ResGroupAo resGroupAo) {
        Integer success = groupService.addGroupList(resGroupAo);
        if (success <= 0) {
            return CommonResult.Fail(BaseErrorCode.ERROR_ADD);
        }
        return CommonResult.Ok();
    }


    /**
     * 分组管理的修改列表接口
     *
     * @param resGroupAo
     * @return
     */
    @PostMapping("/editGroupList")
    public BaseResult editPlaylist(@RequestBody ResGroupAo resGroupAo) {
        boolean success = groupService.editGroupList(resGroupAo);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_UPDATE);
        }
        return CommonResult.Ok();
    }

    /**
     * 分组管理的删除列表接口
     *
     * @param resGroupAo
     * @return
     */
    @PostMapping("/removeGroupList")
    public BaseResult removeGroupList(@RequestBody ResGroupAo resGroupAo) {
        boolean success = groupService.removeGroupList(resGroupAo.getIds());
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_REMOVE);
        }
        return CommonResult.Ok();
    }

    /**
     * 分组管理的设备更改设备组接口
     *
     * @param resGroupAo
     * @return
     */
    @PostMapping("/editDeviceOfGroup")
    public BaseResult editDeviceOfGroup(@RequestBody ResGroupAo resGroupAo) {
        boolean success = groupService.editDeviceOfGroup(resGroupAo);
        if (!success) {
            return CommonResult.Fail(BaseErrorCode.ERROR_UPDATE);
        }
        return CommonResult.Ok();
    }


    /**
     * 课内查看设备组状态
     *
     * @param resContentGroupAo
     * @return
     */
    @PostMapping("/queryClassGroup")
    public BaseResult<ResGroup> queryClassGroup(@RequestBody ResContentGroupAo resContentGroupAo) {
        return groupService.queryClassGroup(resContentGroupAo);
    }
}
